import os

def batch_rename(directory, prefix='', suffix=''):
    """
    批量重命名指定目录中的文件，可添加前缀或后缀。
    
    :param directory: 文件所在的目录路径
    :param prefix: 文件名前缀
    :param suffix: 文件名后缀
    """
    try:
        # 遍历目录中的所有文件
        for filename in os.listdir(directory):
            file_path = os.path.join(directory, filename)
            
            # 检查是否为文件
            if os.path.isfile(file_path):
                # 分离文件名和扩展名
                name, ext = os.path.splitext(filename)
                # 构建新的文件名，将后缀加在扩展名前面
                new_filename = f"{prefix}{name}{suffix}{ext}"
                new_file_path = os.path.join(directory, new_filename)
                
                # 重命名文件
                os.rename(file_path, new_file_path)
                print(f"Renamed: {filename} -> {new_filename}")
    except Exception as e:
        print(f"Error: {e}")

if __name__ == "__main__":
    directory = input("Enter the directory path: ")
    prefix = input("Enter the prefix (leave blank if none): ")
    suffix = input("Enter the suffix (leave blank if none): ")
    
    batch_rename(directory, prefix, suffix)